import { LOGIN_SUCCESS, LOGIN_SECOND, LOGIN_ERROR, LOGIN_USER, NO_SESSION, LOG_OUT } from "../actions/types";

const INITIAL_STATE = {
  status: "false",
  error: '',
  user:null,
  loading: true
};
export default function(state = INITIAL_STATE, action) {
  switch (action.type) {
    case LOGIN_USER:
      return { ...state, loading: true, error: '' };
    case LOGIN_SUCCESS:
      // console.log(action.payload.data.user)
      return {
        ...INITIAL_STATE,
        status: "success",
        loading: false,
        user: action.payload.data.user
      };
    case LOGIN_SECOND:
      return {
        ...INITIAL_STATE,
        status: "second",
        loading: false,
        user: action.payload.data.user
      };
    case LOGIN_ERROR:
      return { ...state, status: "false", loading: false, error: action.payload };
    case NO_SESSION:
      return { ...INITIAL_STATE, loading: false, error: action.payload };
    case LOG_OUT:
      return { ...INITIAL_STATE, loading: false, status: "false",user: null };
    default:
      return state;
  }
}
